<template>
	<view class="content">
		<text style="font-size: 50rpx;">子组件B</text>
		<view class="b-box">
			CompA传进来的值：
			<text style="background-color: blue;color: white;">{{result}}</text>
		</view>
		<view class="b-box" >
			<text>回传值：</text>
			<input type="text" v-model="callbackValue" style="color: yellow;background-color:darkgray;" />
			<button @click="sendOutside()" size="mini">回传</button>
		</view>
	</view>
	
</template>

<script>
	export default {
	  name: "compB",
	  data() {
	    return {
	      result: '', // ✅初始化 result
	      callbackValue: '' // ✅初始化 callbackValue
	    };
	  },
	  created() {
	    uni.$on('getIntent', (msg) => {
	      console.log("----CompB----getIntent----->" + msg);
	      this.result = msg;
	    }); 
	  },
	  methods: {
	    sendOutside() {
	      console.warn("----ComB----sendOutside------>" + this.callbackValue);
	      this.$emit('callBackFun', this.callbackValue);
	    }
	  }
	}
</script>

<style>
	.content {
		margin: 20rpx 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: orange;
	}

	.b-box {
		margin: 10rox 20rpx 50rpx;
		display: flex;
		width: 100%;
		margin: 30rpx;
	}
	
</style>